%{
    #include <iostream>
	#include "common.h"
	#include "enumdeclarations.h"
    #include "parser.h"
	
    using namespace std;
%}

letter				[a-zA-Z]
digit				[0-9]
ident				{letter}({letter}|{digit})*
integer_number 		{digit}+
real_number	 		{digit}+"."{digit}+([eE][-+]?{digit}+)?
relation_operator	"<"|"<="|"="|">="|">"|"<>"
assignment_operator	":="

%%
[[:blank:]\r] {/* SKIP SPACES AND TABULATIONS*/}

[\n] {
	cout << "LEXER FOUND new line" << endl;
}

"program" {
	cout << "LEXER FOUND program" << endl;
	return TOKEN_PROGRAM; 
}

"var" { 
	cout << "LEXER FOUND var" << endl;
	return TOKEN_VAR; 
}

"begin"	{
	cout << "LEXER FOUND begin" << endl;
	return TOKEN_BEGIN;
}

"end" {
	cout << "LEXER FOUND end" << endl;
	return TOKEN_END;	
}

{assignment_operator} {
	cout << "LEXER FOUND assignment_operator" << endl;
	return TOKEN_OP_ASSIGN;
}

{relation_operator}	{
	cout << "LEXER FOUND relation_operator" << endl;
	return TOKEN_OP_REL;
}	

"integer" { 
	cout << "LEXER FOUND integer" << endl;
	return TOKEN_TYPE_INT;
}
		
"real"	{ 
	cout << "LEXER FOUND real" << endl;
	return TOKEN_TYPE_REAL;
}

"read" {
	cout << "LEXER FOUND read" << endl;
	return TOKEN_READ;
}

"write"	{
	cout << "LEXER FOUND write" << endl;
	return TOKEN_WRITE;
}														

{integer_number} {
	cout << "LEXER FOUND integer_number" << endl;
	yylval = symbolTable.insertNumber(yytext);
	return TOKEN_NUBER_INT;
}

{real_number}	{		
	cout << "LEXER FOUND real_number" << endl;
	yylval = symbolTable.insertNumber(yytext);
	return TOKEN_NUBER_REAL;
}		

{ident} {
    yylval = symbolTable.insertIdentifier(yytext);
	cout << "LEXER FOUND ident" << endl;
	return TOKEN_IDENTIFIER;					
}

"+" {
	return TOKEN_PLUS;
}

"-" {
	return TOKEN_MINUS;
}	

"*" {
	return TOKEN_MULTIPLY;
}

"/" {
	return TOKEN_DIVIDE;
}
. {
	cout << "LEXER unknown: |" << yytext << "|" << endl;
	return *yytext;
}
%%